1 package uk.ac.roe.antigen.dialogs;
2
3 import java.awt.BorderLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.io.IOException;
7 import java.net.URL;
8
9 import javax.swing.BorderFactory;
10 import javax.swing.ImageIcon;
11 import javax.swing.JButton;
12 import javax.swing.JPanel;
13 import javax.swing.JScrollPane;
14 import javax.swing.JTextPane;
15 import javax.swing.border.BevelBorder;
16 import javax.swing.border.TitledBorder;
17 import javax.swing.event.HyperlinkEvent;
18 import javax.swing.event.HyperlinkListener;
19 import javax.swing.text.html.HTMLEditorKit;
20
21 import uk.ac.roe.antigen.builder.InfoDisplay;
22 import uk.ac.roe.antigen.utils.BrowserLauncher;
23 import uk.ac.roe.antigen.utils.Config;
24
25 /***
26
27 */
28 public class InfoFrame extends AntigenFrame implements InfoDisplay {
29
30
31 private JTextPane textArea;
32 private JScrollPane jScrollPane1;
33 private JButton jButton1;
34 private JPanel buttons2;
35 private String text;
36
37 private JButton jButton2;
38
39 /***
40 * Auto-generated main method to display this JDialog
41 */
42 public static void main(String[] args) {
43 InfoFrame inst = new InfoFrame("Test message<BR><a href='http://127.0.0.1:8080'>local tomcat</a>");
44 inst.setVisible(true);
45 }
46
47 public InfoFrame(String text) {
48 super();
49 this.text = text;
50 initGUI2();
51 }
52
53
54 private void initGUI2() {
55 try {
56 {
57 jScrollPane1 = new JScrollPane();
58 workPanel.add(jScrollPane1, BorderLayout.CENTER);
59 jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
60 {
61 textArea = new JTextPane();
62 textArea.setEditorKit(new HTMLEditorKit());
63 jScrollPane1.setViewportView(textArea);
64 textArea.setText(text);
65 String borderTitle = Config.getProperty("antigen.dialog.bordertitle","antigen");
66 textArea.setBorder(BorderFactory.createTitledBorder(
67 BorderFactory.createEtchedBorder(
68 BevelBorder.LOWERED,
69 null,
70 null),
71 borderTitle,
72 TitledBorder.LEADING,
73 TitledBorder.TOP,
74 new java.awt.Font("Eurostile", 0, 12),
75 new java.awt.Color(0, 0, 255)));
76 textArea.setEditable(false);
77
78 }
79 }
80 {
81 buttons2 = new JPanel();
82 southPanel.add(buttons2, BorderLayout.SOUTH);
83 buttons2.setOpaque(false);
84 {
85 jButton2 = new JButton();
86 buttons2.add(jButton2);
87 jButton2.setText("Back");
88 jButton2.setEnabled(false);
89 jButton2.setIcon(new ImageIcon(getClass().getClassLoader()
90 .getResource("img/leftarrow.png")));
91 jButton2.addActionListener(new ActionListener() {
92 public void actionPerformed(ActionEvent evt) {
93 logger.fine("Resetting text back");
94 textArea.setDocument(textArea.getEditorKit().createDefaultDocument());
95 textArea.setText(text);
96 jButton2.setEnabled(false);
97 }
98 });
99 jButton1 = new JButton();
100 buttons2.add(jButton1);
101 jButton1.setText("Next");
102 jButton1.setIcon(new ImageIcon(getClass().getClassLoader()
103 .getResource("img/rightarrow.png")));
104 jButton1.addActionListener(new ActionListener() {
105 public void actionPerformed(ActionEvent evt) {
106 OKpressed = true;
107 }
108 });
109 }
110 }
111 } catch (Exception e) {
112 e.printStackTrace();
113 }
114
115 textArea.addHyperlinkListener(new HyperlinkListener() {
116
117 public void hyperlinkUpdate(HyperlinkEvent hle) {
118 if (hle.getEventType()!=HyperlinkEvent.EventType.ACTIVATED) {
119 return;
120 }
121 URL url = hle.getURL();
122 logger.fine("Hyperlink event "+hle+" url="+url);
123
124 try {
125
126 BrowserLauncher.openURL(url.toString());
127 return;
128 } catch (IOException e) {
129 logger.info("Unable to open browser - using internal, inferior browsing");
130 }
131
132 try {
133 textArea.setPage(url);
134 jButton2.setEnabled(true);
135 } catch (IOException io) {
136 logger.warning("Unable to open page "+url+","+io.getMessage());
137 }
138 }
139
140 });
141 }
142
143 boolean OKpressed=false;
144 public void showAndWaitForResponse() {
145 show();
146 while (!OKpressed) {
147 try {
148 Thread.sleep(200);
149 } catch (InterruptedException ie) {}
150 }
151 dispose();
152 }
153
154 /***
155 * Time to clean up and closedown
156 */
157 public void shutDown() {
158 logger.info("Info window closing");
159 }
160
161 }